package com.smforj.ssm.sys.service.impl;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.smforj.ssm.sys.dao.IUserInfoDAO;
import com.smforj.ssm.sys.model.po.UserInfoPO;
import com.smforj.ssm.sys.service.IUserInfoService;

/**
 * Created by shibiao on 16/10/1.
 */
@Service
public class UserInfoServiceImpl implements IUserInfoService {
    private final static Logger logger = LoggerFactory.getLogger(UserInfoServiceImpl.class);

    @Resource
    private IUserInfoDAO userInfoDAO;

    @Override
    public boolean insertUserInfo(String userName, String password) {
        UserInfoPO userInfoPO = new UserInfoPO();
        userInfoPO.setUserName(userName);
        userInfoPO.setPassword(DigestUtils.md5Hex(password));
        int result = userInfoDAO.insertUserInfo(userInfoPO);
        return result>0?true:false;
    }

    @Override
    public boolean isLogin(String userName, String password) {
        UserInfoPO userInfoPO = userInfoDAO.getUserInfoByUserName(userName);
        if (userInfoPO==null){
            return false;
        }
        if (!userInfoPO.getPassword().equals(DigestUtils.md5Hex(password))){
            return false;
        }
        return true;
    }
}
